import { useState } from "react";

export function useCountdown(initTime = 60) {
    const [count, setCount] = useState(initTime);
    const CountDown = () => {
        const timer = setInterval(() => {
            setCount((count) => {
                if (count > 0) {
                    return count - 1;
                } else {
                    clearInterval(timer);
                    return 0;
                }
            })
        }, 1000)
    }
    return {
        count,
        CountDown
    }
}